#!/bin/sh
# Copyright (c) 2012, bkil.hu
# This program is free software and can be distributed under the terms of
# the GNU General Public License v2,
# see COPYING for detailed licensing terms.
# created on 2012-03-11
#
# Verifies if the given user aliases are available on DDNS.
# Supported providers:
# * no-ip.org
# * dyns.cx

. `dirname "$0"`/parallel.sh.inc

main() {
 if [ $# -lt 1 ] ; then
  cat <<EOF >&2
Usage: `basename $0` [<user_1> [<user_2> ...]]
Checks if the specified subdomains are available for DDNS.
EOF
  exit 1
 fi
 job_init || exit 1
 local NOIP="hopto.org no-ip.org zapto.org"
 local YI="yi.org"
 echo "info: main for fork_job"
 for USER in $@
 do
  for HOST in $DYNS $NOIP $YI
  do
   fork_job try_ping_ip $USER.$HOST
  done
 done
 join_jobs 4
}

try_ping_ip() {
 local URL=$1
 printf -- "$URL "
 if ! \
  ping -qc1 -w1 -- $URL 2>/dev/null |
  grep -oE "\(([0-9]+\.){3}[0-9]+\)"
 then
  echo "-"
 fi
}

main "$@"
